<?php

namespace App\Http\Controllers\Strator;

use App\Http\Controllers\Controller;
use App\Models\Strator\StratorFeedBack;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class StratorFeedBackController extends Controller
{
    protected Request $request;
    protected Model $model;

    public function __construct(Request $request,StratorFeedBack $stratorFeedBack)
    {
        $this->request=$request;
        $this->model = $stratorFeedBack;
    }

    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $perPage=$this->request->per_page??10;
        $list=$this->model->modelSearch($this->request,$this->model)
            ->orderByDesc('id')
            ->paginate($perPage);
        return $this->success($list);
    }
    public function store()
    {
        $data=$this->request->all();
        $data['ip']=$this->request->ip();
        $this->model->fill($data);
        $this->model->save();
        $this->saveOperationLog('添加产品属性');
        return $this->success(['id'=>$this->model->id]);
    }
    public function show()
    {
        $model=$this->model->findOrFail($this->request->id);
        return $this->success($model);
    }
    public function update()
    {
        $model=$this->model->findOrFail($this->request->id);
        $data=$this->request->except($this->updateExcept());
        $model->fill($data);
        $model->save();
        $this->saveOperationLog('修改产品属性');
        return $this->successMsg();
    }
    //
    public function updateExcept():array
    {
        return [
            'id',
        ];
    }
    public function destroy()
    {
        $model=$this->model->findOrFail($this->request->id);
        $model->delete();
        return $this->successMsg('删除成功');
    }


}
